package com.fzy.core.acegi;

import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;

import ex.app.system.service.LoginService;

public class UserDetailsServiceImpl implements UserDetailsService {
	protected final Logger log = Logger.getLogger(getClass());

	LoginService loginService;

	public UserDetails loadUserByUsername(String userName,String userFlag)
			throws UsernameNotFoundException, DataAccessException {
			
		if(log.isInfoEnabled()){
			log.info("The User Name is "+userName+". The UserFlag is "+userFlag+".");
		}
		if(userFlag!=null&&!userFlag.trim().equals("")){
			if(userFlag.trim().equals("1")){
					//如果是外部用户，使用loginName查找用户
				
				return loginService.getOutsideUser(userName);
			}else{
					//如果是内部用户，使用userid查找用户
				return loginService.getInsideUser(userName);
			}		
		}
		
		return null;
	}

	public UserDetails loadUserByUsername(String arg0)
			throws UsernameNotFoundException, DataAccessException {
		System.out.println("asdfsdfsdf");
		return null;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
}
